
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Family extends JFrame{
    public Family(String userid){

        SQLOperation sql=new SQLOperation();

        setTitle("Family Operation");
        setLayout(null);
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel panel1=new JPanel();

        JLabel title=new JLabel("Family Operation");
        title.setFont(new Font("",Font.BOLD,25));
        panel1.add(title);
        add(panel1,BorderLayout.NORTH);

        JPanel search=new JPanel();
        JLabel attri=new JLabel("SearchID:");
        search.add(attri);

        JTextField familySearch=new JTextField(20);
        search.add(familySearch);

        add(search,BorderLayout.CENTER);


        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                new ManagerDefaultFrame(userid);
            }
        });

        JButton list=new JButton("List All");
        list.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // LIST ALL
                new FamilyList(userid);

            }
        });

        JButton enter=new JButton("Search");
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String[] attributes={"familyID"};
                Object[][] result=sql.search("Family",attributes,"familyID",familySearch.getText());

                if(result.length==0){
                    //unfound

                    JOptionPane.showMessageDialog
                            (null, "Invalid Family ID!","Wrong ID",JOptionPane.ERROR_MESSAGE);

                }
                else{

                    new FamilySearchResult(userid,familySearch.getText());
                    //list family detail
                }
            }
        });
        JPanel buttons=new JPanel();
        buttons.add(back);
        buttons.add(list);
        buttons.add(enter);

        add(buttons,BorderLayout.SOUTH);

        setSize(350,200);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);


    }
}
